<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get field information</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mssql-fetch-field" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_fetch_field</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_fetch_field</span> &mdash; <span class="dc-title">Get field information</span></p>

 </div>
 
 <div id="function.mssql-fetch-field-refsynopsisdiv">
  <div class="warning"><strong class="warning">Warning</strong>
   
<p class="para">
 This function was <em class="emphasis">REMOVED</em> in PHP 7.0.0.
</p>
<p class="para">
 Alternatives to this function include:
</p>

   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pdostatement.getcolumnmeta.html" class="function">PDOStatement::getColumnMeta()</a></span></li>
    <li class="member"><span class="function"><a href="sqlsrv_field_metadata.html" class="function">sqlsrv_field_metadata()</a></span></li>
    <li class="member">
     The various odbc_field_* functions in the
     <a href="book.uodbc.html" class="link">unified ODBC driver</a>.
    </li>
   </ul>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mssql-fetch-field-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mssql_fetch_field</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$field_offset</code><span class="initializer"> = -1</span></span>
  ] ) : <span class="type">object</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_fetch_field()</strong></span> can be used in order to
   obtain information about fields in a certain query result. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-fetch-field-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">result</code></dt>

     <dd>

      <p class="para">
       The result resource that is being evaluated. This result comes from a
       call to <span class="function"><a href="mssql_query.html" class="function">mssql_query()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">field_offset</code></dt>

     <dd>

      <p class="para">
       The numerical field offset. If the field offset is not specified, the
       next field that was not yet retrieved by this function is retrieved. The
       <code class="parameter">field_offset</code> starts at 0.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-fetch-field-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an object containing field information.
  </p>
  <p class="para">
   The properties of the object are:
  </p>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     name - column name.  if the column is a result of a function,
     this property is set to computed#N, where #N is a serial
     number.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     column_source - the table from which the column was taken
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     max_length - maximum length of the column
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     numeric - 1 if the column is numeric
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     type - the column type.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-fetch-field-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1754">
    <p><strong>Example #1 <span class="function"><strong>mssql_fetch_field()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;MSSQL&nbsp;and&nbsp;select&nbsp;the&nbsp;database<br /></span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'MANGO\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'php'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Send&nbsp;a&nbsp;select&nbsp;query&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;*&nbsp;FROM&nbsp;[php].[dbo].[persons]'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Construct&nbsp;table<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;h3&gt;Table&nbsp;structure&nbsp;for&nbsp;\'persons\'&lt;/h3&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;table&nbsp;border="1"&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Table&nbsp;header<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;thead&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;tr&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;Field&nbsp;name&lt;/td&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;Data&nbsp;type&lt;/td&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;Max&nbsp;length&lt;/td&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;/tr&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;/thead&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Dump&nbsp;all&nbsp;fields<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;tbody&gt;'</span><span style="color: #007700">;<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">mssql_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);&nbsp;++</span><span style="color: #0000BB">$i</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Fetch&nbsp;the&nbsp;field&nbsp;information<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$field&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_fetch_field</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Print&nbsp;the&nbsp;row<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;tr&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$field</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'&lt;/td&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strtoupper</span><span style="color: #007700">(</span><span style="color: #0000BB">$field</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">type</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&lt;/td&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;td&gt;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$field</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">max_length&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'&lt;/td&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;/tr&gt;'</span><span style="color: #007700">;<br />}<br /><br />echo&nbsp;</span><span style="color: #DD0000">'&lt;/tbody&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;/table&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Free&nbsp;the&nbsp;query&nbsp;result<br /></span><span style="color: #0000BB">mssql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-fetch-field-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mssql_field_seek.html" class="function" rel="rdfs-seeAlso">mssql_field_seek()</a> - Seeks to the specified field offset</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>